import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { RootState } from ".";

export interface GeneralState {
  loading: boolean;
  spinning: boolean;
}

const initialState: GeneralState = {
  loading: false,
  spinning: false,
};

const generalSlice = createSlice({
  name: "general",
  initialState,
  reducers: {
    setLoading: (state, action: PayloadAction<boolean>) => {
      state.loading = action.payload;
    },
    setSpinning: (state, action: PayloadAction<boolean>) => {
      state.spinning = action.payload;
    },
  },
});

export const { setLoading, setSpinning } = generalSlice.actions;

export const selectGeneralState = (state: RootState) => state.general;

export default generalSlice.reducer;
